<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!--Hier fuegt man seinen Arbeitsgeber  oder Firmennamen ein und beschreibt von wann bis wann man in der Firma gearbeitet hat... -->
<%String file="username.jsp",method="get"; %>
<%@page import="db.DBMain"%>
<%RequestParser.send_action_file=file;
RequestParser.send_method=method;%>
<%@page import="html.RequestParser"%>
<%@page import="db.tables.DBTypeTable"%>
<%@page import="db.tables.DBUserNameTable"%>
<%@page import="util.Constant"%>
<%@page import="java.sql.Date"%>
<script type="text/javascript"><!--

<%
Long user_id=0L;//session.getAttribute(Constant.USERID);

RequestParser usernameParser=new RequestParser(request,file,method);
usernameParser.isAdmin(true);
usernameParser.setAdd(Constant.Content.ADD_USERNAME);
usernameParser.setContent(Constant.Content.USERNAME);
usernameParser.setSubmit(Constant.Content.SUBMIT_USERNAME);
usernameParser.setDelete(Constant.Content.DELETE_USERNAME);
usernameParser.setInput(new String[]{Constant.Content.INPUT_USERNAME,Constant.Content.INPUT_START,Constant.Content.INPUT_END});
usernameParser.setInsert_columns(new String[]{DBUserNameTable.USER_ID_COL,DBUserNameTable.USER_NAME_COL,DBUserNameTable.START_DATE_COL,DBUserNameTable.END_DATE_COL});
usernameParser.setDisplay_columns(new String[]{DBUserNameTable.USER_NAME_ID_COL,DBUserNameTable.USER_NAME_COL});
usernameParser.setPk_column(DBUserNameTable.USER_NAME_ID_COL);
usernameParser.setTable(DBMain.getUserNameTable());
usernameParser.setFk_column(DBUserNameTable.USER_ID_COL);
usernameParser.setFk_id(user_id);

//#########################################################
// FIXME edit so it is only available to admins!
// #########################################################
if (request.getParameter(usernameParser.getSubmit()) != null) {
	if (RequestParser.areAllParametersNotNull(request, usernameParser.getInput())) {
		int i=0;
		String[] req=usernameParser.getInput();
		Object[] result = new Object[req.length+1];
		//DBIsActiveTable.USER_ID_COL 
		result[i]=user_id;
		//DBIsActiveTable.ACTIVITY_ID_COL
		i++;
		result[i]=request.getParameter(Constant.Content.INPUT_USERNAME);
		//DBIsActiveTable.START_DATE_COL,
		i++;
		result[i]=Date.valueOf(request.getParameter(Constant.Content.INPUT_START));
		//DBIsActiveTable.END_DATE_COL 
		i++;
		String t=request.getParameter(Constant.Content.INPUT_END);
		if(t!=null&&!t.equals("")&&!t.equalsIgnoreCase("null"))
			result[i]=Date.valueOf(t);
		else result[i]=null;
		usernameParser.setPk_id(usernameParser.getTable().insertGetPK(usernameParser.getInsert_columns(), result));
	} else if (RequestParser.areSomeParametersNotNull(request, usernameParser.getInput())) {
		// TODO Error output because only one parameter is set -
		// needed are both!
	}
}

// #########################################################
// FIXME add additional functions so it is i.e. possible to delete
// only all related towns or vice versa
// and same as above: only for Admins!!
// #########################################################
if (request.getParameter(usernameParser.getDelete()) != null && usernameParser.getPk_id() != null) {
	usernameParser.getTable().delete(usernameParser.getPk_column(), usernameParser.getPk_id());
}

usernameParser.setArray(usernameParser.getTable().getSelect(usernameParser.getDisplay_columns(), usernameParser.getFk_columns(), usernameParser.getFk_ids()));

%>
//
--></script>
<form name="<%=usernameParser.getContent() %>" action="<%=usernameParser.getSend_action_file() %>" method="<%=usernameParser.getSend_method()%>">
<select name="<%=usernameParser.getContent() %>">
	<%usernameParser.printOptionList(out); %>
</select>
	<input name="<%=usernameParser.getDelete() %>" value="<%=Constant.Content.DELETE %>" type="submit"/>
	<table>
	<tr><td>Name</td></tr>
	<tr>
	<td><input name="<%=usernameParser.getInput()[0] %>" type="text"/></td>
	</tr>
	<tr> 
         <td width="17%">Beginn:</td>
         <td width="83%">
           <input type="text" name="<%=Constant.Content.INPUT_START%>" size="11" value="">
		<a href="javascript: void(0);" onmouseover="if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;" 
		onmouseout="if (timeoutDelay) calendarTimeout();window.status='';" onclick="g_Calendar.show(event,'<%=usernameParser.getContent() %>.<%=Constant.Content.INPUT_START%>',true,'yyyy-mm-dd'); return false;">
		<img src="../images/calendar.gif" name="imgCalendar" width="34" height="21" border="0" alt=""></a>
         </td>
             <tr> 
         <td width="17%">Ende: </td>
         <td width="83%">
           <input type="text" name="<%=Constant.Content.INPUT_END%>" size="11" value="">
		<a href="javascript: void(0);" onmouseover="if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;" 
		onmouseout="if (timeoutDelay) calendarTimeout();window.status='';" onclick="g_Calendar.show(event,'<%=usernameParser.getContent() %>.<%=Constant.Content.INPUT_END%>',true,'yyyy-mm-dd'); return false;">
		<img src="../images/calendar.gif" name="imgCalendar" width="34" height="21" border="0" alt=""></a>
         </td>
         <tr>
	</table>
    <input type="hidden" name="<%=usernameParser.getContent() %>" value="<%=usernameParser.getPk_id()%>"/>
    <input name="<%=usernameParser.getSubmit() %>" type="submit"/>
	<input type="reset" name="Zur&uuml;cksetzen" value="Zur&uuml;cksetzen">
</form>